import re

def update_url_param(url, params):
    pairs = ""
    for key in params.keys():
        pairs += "&" + key + "=" + params[key]
    if '?' in url:
        url += pairs
    else:
        pairs = '?' + pairs[1:]
        url += pairs
    return url


def clean(var):
    return var.decode("utf-8")


def complete_url(url):
    reg = re.compile(r"^http://.*")
    reg2 = re.compile(r"^https://.*")
    if not (reg.search(url) or reg2.search(url)):
        url = "http://"+url
    return url